<?php
//TODO CONSERTAR OS CSS
/**
 * 
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.View.Layouts
 * @since         CakePHP(tm) v 0.10.0.1076
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

?>
<!DOCTYPE html>
<html>
<head>
	<?php echo $this->Html->charset(); ?>
	<title>
		<?php echo $sys_name; ?>
		<?php echo '- '.$title_for_layout; ?>
	</title>
	<?php
		echo $this->Html->meta('icon');
		echo $this->Html->script('jquery-1.9.0.min.js');
		echo $this->Html->script('jquery-ui-1.10.3.custom.js');
		echo $this->Html->script('jquery.cookie.js');
		echo $this->Html->css('cake.generic');
		echo $this->Html->css('forms');
		echo $this->Html->css('scige');
		echo $this->Html->css('smoothness/jquery-ui-1.10.3.custom.css');
		echo $this->Html->css('jquery-ui-timepicker-addon.css');
		echo $this->fetch('meta');
		echo $this->fetch('css');
		echo $this->fetch('script');
	?>
	<script type="text/javascript">
	jQuery(function(){
		$.cookie('menustate', null);
		<?php // TODO Rever cookies aqui ?>
		$( ".accordion" ).accordion({
			heightStyle: "content",
			activate: function(event,ui) {
				var hid = ui.newHeader.children('a').attr('id');
				if (hid === undefined) {
					$.cookie('menustate', null, { path: '/' });
				} else {
					alert('salvando');
					$.cookie('menustate', hid, { path: '/' });
				}
			}
		});
		if($.cookie('menustate')) {
	         $('.menu').accordion('option', 'animated', false);
	         $('.menu').accordion('activate', $('#' + $.cookie('menustate')).parent('h3'));
	         $('.menu').accordion('option', 'animated', 'slide');
		}
	});
	</script>
</head>
<body>
	<div id="container">
		<div id="header">
			<h1><?php echo $this->Html->link($sys_name, '/'); ?></h1>
		</div>
		<div class="actions menu border">
				<?php if(!$usuario_sessao){
					echo $this->element('menu/publico');
				} 
				else if($usuario_sessao && $usuario_sessao['tipo'] == ADMIN){
					echo $this->element('menu/admin');
				}else if($usuario_sessao && $usuario_sessao['tipo'] == USUARIO){
					echo $this->element('menu/usuario');
				}else if($usuario_sessao && $usuario_sessao['tipo'] == REVISOR){
					echo $this->element('menu/revisor');
				}
				$menu = $this->requestAction('/userpages/menu');
				?>
				<span style="color: red;">InfoPaginas</span>
				<ul title="userpages">
				<?php foreach ($menu as $entry){
					if($entry['Userpage']['menu']){
						echo '<li>'.$this->Html->link($entry['Userpage']['titulo'],'/paginas/'.$entry['Userpage']['caminho']).'</li>';
					}
				}?>
				</ul>
			
		</div>
		<div id="content">
			<div id="user_info">
				<?php //pr($usuario_sessao); ?>
				<?php if(!isset($login_page)){
						 if (isset($usuario_sessao)){
							echo 'Bem vindo ';
							echo $this->Html->link($usuario_sessao['login'], '/');
							echo __('('.$this->Html->link(__('Sair'), '/logout').')');
						 }
					   	 else 
							echo $this->Html->link(__('Fazer login'), array('controller' => 'login'));
				} ?>
			</div>
			<?php //pr($usuario_sessao); ?>
			<?php //echo $usuario_sessao['login']; ?>
			<?php echo $this->Session->flash(); ?>
			<?php echo $this->fetch('content'); ?>
		</div>
		<div id="footer">
			<?php echo $this->Html->link(
					$this->Html->image('cake.power.gif', array('alt' => $sys_name, 'border' => '0')),
					'http://www.cakephp.org/',
					array('target' => '_blank', 'escape' => false)
				);
			?>
		</div>
	</div>
	<?php echo $this->element('sql_dump'); ?>
</body>
</html>
